//
//  ZJMineSetController.m
//  ZiJinLian
//
//  Created by lc on 2017/3/23.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "ZJMineSetController.h"
#import "ZJBaseNavControllerViewController.h"
#import "MineDataViewController.h"
#import "SecurityViewController.h"
#import "LanguageViewController.h"
@interface ZJMineSetController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation ZJMineSetController

-(void)createView{
    [self initTitle:MyString(@"设置")];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"home_nav_bg"] forBarMetrics:UIBarMetricsDefault];
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH-49) style:UITableViewStyleGrouped];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    UIView* view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, MainW, 0.001)];
    _tableView.tableHeaderView=view;
    _tableView.separatorColor=SeparatorColor;
    _tableView.separatorInset=UIEdgeInsetsZero;
    _tableView.separatorInset=UIEdgeInsetsMake(0, 0, 0, 0);
    [self.view addSubview:_tableView];
    UIButton* addAddressBtn=[UIButton creatBtn];
    [addAddressBtn ZJButtonStyleWithBgImg:@"icon_plus" withTitle:MyString(@"退出当前账户")];
    [addAddressBtn addTarget:self action:@selector(exitAccount) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:addAddressBtn];
    [addAddressBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.mas_equalTo(50);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
 
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   static NSString* ID=@"cell";
    
    UITableViewCell* cell =[tableView dequeueReusableCellWithIdentifier:ID];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    if (indexPath.row==0) {
        cell.textLabel.textColor=TextColor3;
        cell.textLabel.font=FontAndStyle14;
        cell.imageView.image=[UIImage imageNamed:@"icon_porfile"];
        cell.textLabel.text=MyString(@"个人资料");
    }else if (indexPath.row==2){
        cell.textLabel.textColor=TextColor3;
        cell.textLabel.font=FontAndStyle14;
        cell.imageView.image=[UIImage imageNamed:@"icon_language"];
        cell.textLabel.text=MyString(@"语言");
    }else{
        cell.textLabel.textColor=TextColor3;
        cell.textLabel.font=FontAndStyle14;
        cell.imageView.image=[UIImage imageNamed:@"icon_account"];
        cell.textLabel.text=MyString(@"账户与安全");
    }
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
            //个人资料
        {
            MineDataViewController *vc=[[MineDataViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
           
            break;
        case 1:
        {
            SecurityViewController *vc=[[SecurityViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }

            //账户与安全
            
            break;
        case 2:
        {
            LanguageViewController *vc=[[LanguageViewController alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
        }
            
            //切换语言
            
            break;
        default:
            break;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 50;
}
-(void)doOpeartion{
    [_btn addTarget:self action:@selector(exitAccount) forControlEvents:UIControlEventTouchUpInside];


}





#pragma mark 退出账户
-(void)exitAccount{
    UIAlertView* alter =[[UIAlertView alloc]initWithTitle:MyString(@"确定退出账户?") message:nil delegate:self cancelButtonTitle:MyString(@"确定") otherButtonTitles:MyString(@"取消"), nil];
    [alter show];
    
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
    if (buttonIndex==0) {
        EMError *error = [[EMClient sharedClient] logout:YES];
        if (!error) {
            NSLog(@"退出成功");
        }
        [ZJUserDefaultsTools clearWithoutAvatar];
        [self.navigationController popViewControllerAnimated:YES];
    }
}


@end
